package controllers;

import java.io.IOException;
import java.net.BindException;
import java.sql.SQLException;
import java.util.HashMap;

import javax.swing.JOptionPane;

import ocsf.server.AbstractServer;
import ocsf.server.ConnectionToClient;

/*
 * Class that holds all the thread and clients and is managing the messages
 */


public class EchoServer extends AbstractServer{

	final public static int DEFAULT_PORT = 5555;
	Object message;
	
	
	public EchoServer(int port) {
		super(port);
	}

	
	
	@Override
	protected void handleMessageFromClient(Object msg, ConnectionToClient client) {
		
		 try {
				
			 DBController DBcontroller = new DBController(msg , client);
			 
			 
		} catch (SQLException | IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
	}
	
	protected void serverStarted()
	  {
		  
		 
	    System.out.println("Server listening for connections on port " + getPort());
	 /*   try {
			allUnconnested();
			(new Thread(new Lendingreport())).start();
			(new Thread(new PDFTrans())).start();
			(new Thread(new LendReportMonth())).start();
			(new Thread(new CheckLending())).start();  
			//(new Thread(new MessageActivityReport())).start();   we need this line in order to crate daily report
			
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
	  }
	  
	  private void allUnconnested() throws SQLException {
		  DBConnection conn= new DBConnection();
		  java.sql.PreparedStatement psl = conn.getDBConnection().prepareStatement("Update sgi_system.users SET Status=? ");	
		  psl.setInt(1, 0);
		  psl.executeUpdate();
	}


	  protected void serverStopped()
	  {
	    System.out.println("Server has stopped listening for connections.");
	  }



}